package com.demoapps.client;

import com.demoapps.client.layout.AppLayout;
import com.demoapps.client.mvp.TotalizatorActivityMapper;
import com.demoapps.client.mvp.TotalizatorPlaceHistoryMapper;
import com.demoapps.client.mvp.place.MainPlace;
import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;

public class TotalizatorEntryPoint implements EntryPoint {
	private SimplePanel containerWidget;
	private MainPlace defaultPlace = new MainPlace();
	
	@Override
	public void onModuleLoad() {
		final AppLayout mainLayout = new AppLayout();
		containerWidget = mainLayout.getAppContentHolder();
		
		final ClientFactory clientFactory = GWT.create(ClientFactory.class);
		EventBus eventBus = clientFactory.getEventBus();
		PlaceController placeController = clientFactory.getPlaceController();
		
		ActivityMapper activityMapper = new TotalizatorActivityMapper(clientFactory);
		ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
		activityManager.setDisplay(containerWidget);
		
		TotalizatorPlaceHistoryMapper historyMapper = GWT.create(TotalizatorPlaceHistoryMapper.class);
		PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
		historyHandler.register(placeController, eventBus, defaultPlace);
		
		RootPanel.get().add(mainLayout);
		
		History.newItem("main:");
	}
}
